package com.atguigu.chapter11

object ScanDemo01 {
  //普通函数
  def minus(num1: Int, num2: Int): Int = {
    num1 - num2
  }

  def main(args: Array[String]): Unit = {

    //5 (1,2,3,4,5) =>(5, 4, 2, -1, -5, -10) //Vector(5, 4, 2, -1, -5, -10)
    val i8 = (1 to 5).scanLeft(5)(minus) //IndexedSeq[Int]
    println("i8=" + i8)

    //普通函数
    def add(num1: Int, num2: Int): Int = {
      num1 + num2
    }

    //(1,2,3,4,5) 5 => (20,19,17,14, 10,5) 同样集合中的元素是二元函数的第一个入参
    val i9 = (1 to 5).scanRight(6)(minus) //IndexedSeq[Int]
    println("i9=" + i9)
    // (z: B)(op: (B, A) => B)  -> (z: Int)(op: (Int, Int) => Int)
    val v10 = 1.to(4).scanLeft(2)(testMyFunction)
    print("v10=" + v10)
  }

  def testMyFunction(num1: Int, num2: Int): Int = {
    num1 * num2
  }
}
